<?php if(!defined('HOST'))die('not access');?>
<script >
(function (window) {
// 将小数点清零
var toInteger = function (value) {
value = Math.round(parseFloat(value));
return value;
};
// 保留一位小数点
var toDecimal = function (value) {
value = Math.round(parseFloat(value) * 10) / 10;
if (value.toString().indexOf(".") < 0) {
value = value.toString() + ".0";
}
return value;
}
// 保留两位小数点
var toFloat = function (value) {
value = Math.round(parseFloat(value) * 100) / 100;
if (value.toString().indexOf(".") < 0) {
value = value.toString() + ".00";
}
return value;
}
// 保留两位小数点，一位小数自动补零
var toZero = function (value) {
value = Math.round(parseFloat(value) * 100) / 100;
var xsd = value.toString().split(".");
//Ext.log(xsd.length);
if (xsd.length == 1) {
value = value.toString() + ".00";
return value;
}
if (xsd.length > 1) {
if (xsd[1].length < 2) {
value = value.toString() + "0";
}
return value;
}
}
window.fomatFloat = {
toInteger: toInteger,
toDecimal: toDecimal,
toFloat: toFloat,
toZero: toZero,
};
})(window);
    function loadTableData(params = new Object()){
        params.utype = 1;
        js.ajax(js.getajaxurl('commissionSummary','{mode}','{dir}'),params,function(s){
            var content = "<table id=\"tablemain_{rand}\" class=\"table table-striped table-bordered table-hover\" style=\"margin:0px\">";
            content += "<thead><tr>";
            content += "<th width=\"40\">批次</th>";
            content += "<th width=\"40\">工程类</th>";
            content += "<th width=\"40\">服务类</th>";
            content += "<th width=\"40\">电子卖场</th>";
            content += "<th width=\"40\">货物类</th>";
            content += "<th width=\"40\">合计</th>";
            content += "</tr></thead>";
            content += "<tbody id=\"tbody_{rand}\">";
            $.each(s.lists, function(i, field){
                content += "<tr><td>"+field.name+"</td>";
                var totalTmp = 0;
                $.each(s.type, function(ii, fieldii){
                    content += "<td width=\"40\"><span>"+(field.data[fieldii]=="0"?"0":fomatFloat.toZero(field.data[fieldii]))+"</span></td>";
                    totalTmp += eval(parseFloat(field.data[fieldii])-0);
                });
                totalTmp = fomatFloat.toZero(totalTmp);
                content += "<td><span>"+totalTmp+"</span></td></tr>";
            });
            content += "</tbody>";
            content += "</table>";
            $("#veiw_{rand}").html(content);
        },'get,json',false,'');
    }
</script>

<table>
<tr>
        <td>
            完成时间：
            <input onclick="js.datechange(this,'date')" value="" class="inputs datesss" inputtype="date" readonly="" name="search_sdate" id="search_sdate_{rand}" style="width:110px">
            <input onclick="js.datechange(this,'date')" value="" class="inputs datesss" inputtype="date" readonly="" name="search_edate" id="search_edate_{rand}" style="width:110px">
        </td>
        <td style="padding-left:10px;">
            <button class="btn" id="t_year_{rand}" type="button">年</button>
            <button class="btn" id="t_season_{rand}" type="button">季</button>
            <button class="btn" id="t_month_{rand}" type="button">月</button>
        </td>
        <td style="padding-left:10px;">
            <select class="form-control" id="projectadminer_{rand}">

            </select>
        </td>
        <td nowrap style="padding-left:10px">
            <button class="btn btn-default" onclick="search()" type="button">搜索</button>&nbsp;
            <button class="btn btn-default" onclick="downSummary()" type="button">导出</button>
        </td>
    </tr>
</table>
</div>
<div class="blank10"></div>
<div id="veiw_{rand}"></div>

<script>
    var date=new Date;
    var y = date.getFullYear()
    $('#search_sdate_{rand}').val(y+'-01-01');

    function search() {
        var sdate = $('#search_sdate_{rand}').val();
        var edate = $('#search_edate_{rand}').val();
        var projectadminer=$('#projectadminer_{rand}').val();
        var params = {
            'sdate':sdate,
            'edate':edate,
            'utype':1,
            'projectadminer':projectadminer
        }
        loadTableData(params);
    }

    function downSummary()
    {
        var sdate = $('#search_sdate_{rand}').val();
        var edate = $('#search_edate_{rand}').val();
        var projectadminer=$('#projectadminer_{rand}').val();
        var comid=$('#unit_{rand}').val();
        window.open('./index.php?a=wtjhhzb&m=office|index&d=cg&ajaxbool=true&sdate='+sdate+'&edate='+edate+'&projectadminer='+projectadminer+'&utype=1');
    }

    $(document).ready(function() {
        loadTableData();
        loadProjectadminer();
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth();
        var month = month + 1;
        if(month.toString().length == 1) {
            month = '0' + month;
        }
        var day = date.getDate();
        $("#t_year_{rand}").click(function(){
            var sdate=$('#search_sdate_{rand}').val(year+'-01-01');
            var edate=$('#search_edate_{rand}').val(year+'-12-31');
        });
        $("#t_season_{rand}").click(function(){
            stime = '';
            etime = '';
            switch(true) {
                case (month <= 3):
                    stime = year+'-01-01';
                    etime = year+'-03-31';
                    break;
                case (3 < month <= 6):
                    stime = year+'-04-01';
                    etime = year+'-06-30';
                    break;
                case (6 < month <= 9):
                    stime = year+'-07-01';
                    etime = year+'-09-30';
                    break;
                case (9 < month <= 12):
                    stime = year+'-10-01';
                    etime = year+'-12-31';
                    break;
            }
            var sdate=$('#search_sdate_{rand}').val(stime);
            var edate=$('#search_edate_{rand}').val(etime);
        });
        $("#t_month_{rand}").click(function(){
            var lastDay= new Date(year,month,0).getDate();
            var sdate=$('#search_sdate_{rand}').val(year+'-'+month+'-01');
            var edate=$('#search_edate_{rand}').val(year+'-'+month+'-'+lastDay);
        });
    });

    function loadProjectadminer() {
        $.ajax({ url: "./index.php?a=loadProjectadminner&m=index&d=cg&ajaxbool=true", success: function(obj){
                var ccc ="<option value=''>--项目负责人--</option>";
                obj = JSON.parse(obj);
                data = obj;
                for(i=0;i<data.length;i++){
                    ccc += "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
                };
                $("#projectadminer_{rand}").html(ccc);
            }});
    }
</script>